//
//  CustomButton.m
//  chanyou
//
//  Created by 高爽 on 15-1-14.
//  Copyright (c) 2015年 wanli. All rights reserved.
//

#import "CustomButton.h"
#import "Common.h"
@implementation CustomButton

- (void)drawRect:(CGRect)rect
{
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGColorRef outerTop = [UIColor colorWithRed:0/255.0 green:187/255.0 blue:246/255.0 alpha:1].CGColor;
    CGColorRef outerBottom = [UIColor colorWithRed:0/255.0 green:187/255.0 blue:246/255.0 alpha:1].CGColor;
    
    CGFloat outerMargin = 0.f;
    CGRect outerRect = CGRectInset(self.bounds, outerMargin, outerMargin);
    
    CGMutablePathRef outerPath = createRoundedRectForRect(outerRect, 6.0);// 6.0  圆角
    
    CGContextAddPath(context, outerPath);
    CGContextClip(context);
    
    drawLinearGradient(context, outerRect, outerTop, outerBottom);
    
    CGRect highlightRect = CGRectInset(outerRect, 1.0f, 1.0f);
    
    CGMutablePathRef highlightPath = createRoundedRectForRect(highlightRect, 6.0);
    
    CGContextSaveGState(context);// 1.
    CGContextAddPath(context, outerPath);// 白色亮光
    CGContextAddPath(context, highlightPath);// 白色亮光
    CGContextEOClip(context); // 切角
    
    
    
    CGContextRestoreGState(context);// 2.
    drawCurvedGloss(context, outerRect, 180);
    CFRelease(highlightPath);
}

@end
